<template>
  <div id="main">
    <el-row>
      <el-col :span="17">
        <el-main>
          <div style="height: fit-content">
            <div class="six-action-container">
              <div style="padding: 1rem" class="six-action-item" v-for="(v, i) in taskList" :key="i">
                <div class="bubble" :style="{
                    backgroundImage: `url(${require('@/assets/index_bg/' +
                      (i + 1) +
                      '.png')})`,
                  }">
                  <div class="act-text">
                    <div class="title">{{ v.label }}·待办</div>
                    <div class="todo">
                      {{ v.value }}
                    </div>
                  </div>
                  <div class="bg-to" @click="toRoute(v.url)">更多☞</div>
                  <!-- <div class="bg-cloud">
                                </div> -->
                </div>
              </div>
            </div>
          </div>

          <!-- <div>
                        <div style="height: fit-content;margin: 0px 15px 0 15px;">
                            <div class="bottom-charts-container">
                                <div class="bottom-charts-item">
                                    <el-card style="height: fit-content;margin: 5px;">
                                        <div slot="header">
                                            <span>校区宿舍分布人数统计</span>
                                        </div>
                                        <div style="height: 280px;overflow-y: scroll;">
                                            <div class="campus-dms-count-container">
                                                <div class="campus-dms-count-item" v-for="(v, i) in init_park_list"
                                                    :key="i">
                                                    <circle-progress
                                                        :percentage="(isNaN(v.allIn / v.all) ? 0 : Math.round(v.allIn / v.all * 10000) / 100).toString()"
                                                        :abstract="v.allIn.toString()" :title="(v.campusName + '·' + v.parkName).length > 8 ? v.parkName : v.campusName
                                                            + '·' +
                                                            v.parkName" :shade="progress_color[i]" />

                                                    <div>
                                                        <div class="stuCountText">男生人数
                                                            <span
                                                                :style="v.boyIn >= v.girlIn ? { color: progress_color[i][1] } : {}"
                                                                class="stuCountNumber">
                                                                {{ v.boyIn }}
                                                            </span>
                                                        </div>

                                                        <div class="stuCountText">女生人数
                                                            <span
                                                                :style="v.boyIn < v.girlIn ? { color: progress_color[i][1] } : {}"
                                                                class="stuCountNumber">
                                                                {{ v.girlIn }}
                                                            </span>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>

                                    </el-card>
                                </div>

                                <div class="bottom-charts-item">
                                    <el-card style="margin: 5px;">
                                        <div slot="header">
                                            <span>优秀毕业生情况</span>
                                        </div>
                                        <div style="position: relative;top: -20px;" class="echart" id="mychart2"
                                            :style="myChartStyle"></div>

                                    </el-card>
                                </div>

                            </div>

                        </div>
                    </div> -->
        </el-main>
      </el-col>

      <el-col :span="6">
        <el-main style="padding: 0">
          <el-card style="margin-top: 20px; height: 220px" shadow="always">
            <div slot="header">
              <span>快捷功能</span>
            </div>
            <div style="height: 30vh; position: relative">
              <el-col :span="6" style="text-align: center" v-for="(v, i) in fast" :key="i">
                <div style="width: 100%; height: 11vh" class="fast-act">
                  <el-image :src="v.src" style="position: relative; width: 44.917px; height: 44px"></el-image>
                  <div style="font-size: 14px; position: relative; top: -5px">
                    {{ v.text }}
                  </div>
                </div>
              </el-col>
            </div>
          </el-card>

          <el-card style="margin-top: 20px" shadow="always">
            <div slot="header">
              <span>提醒消息</span>
            </div>
            <el-row style="overflow-y: scroll; height: 200px" v-if="have_msg">
              <el-col style="
                  margin-bottom: 10px;
                  border-bottom: 1px dotted lightblue;
                  cursor: pointer;
                " v-for="(v, i) in msg_list" :key="i" :span="24" @click.native="msgVClick(v.content)">
                <span style="overflow: hidden">{{
                  v.content.length > 20
                    ? v.content.substr(0, 17) + "..."
                    : v.content
                }}</span>
              </el-col>
            </el-row>
            <div style="height: 200px" v-else>暂无消息</div>
          </el-card>

          <el-card style="margin-top: 20px; height: 230px" shadow="always">
            <div slot="header">
              <span>公示栏</span>
            </div>
            <el-row v-if="have_comp">
              <div style="height: 25vh; overflow-y: scroll; overflow-x: hidden">
                <div v-for="(v, i) in comp_list" :key="i" style="cursor: pointer; margin-bottom: 5px">
                  {{ v.submitterName }}--{{ v.projectName }} -- 审核通过
                </div>
              </div>
            </el-row>
            <div v-else>暂无消息</div>
          </el-card>
        </el-main>
      </el-col>
    </el-row>

    <el-dialog title="消息" :visible.sync="msgV" width="30%">
      <span>{{ msg_content }}</span>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="msgV = false">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import { getCompleted } from "@/api/stuCQS/process-center/auditDetails";
import { listMsg } from "@/api/stuCQS/process-center/msg";
import * as echarts from "echarts";

import { countParkStuIn } from "@/api/dormitory/basedata/dormitory";

import { countBiyeYearDept, countXwUnDo } from "@/api/stuCQS/good/apply";

import { groupBy, isEmpty } from "@/api/helpFunc";

import CircleProgress from "@/components/CircleProgress";

export default {
  name: "index-2",
  components: {
    CircleProgress,
  },
  data () {
    return {
      progress_color: [
        ["rgb(71,192,93)", "rgb(142,239,98)"],
        ["rgb(255,135,37)", "rgb(255,179,127)"],
        ["rgb(255,54,125)", "rgb(255,117,159)"],
      ],

      taskList: [
        {
          label: "评优评先审核",
          name: "good",
          value: 0,
          url: "/stuGood/about-good/xw",
        },
        {
          label: "静湖之星审核",
          name: "lake",
          value: 0,
          url: "/stuGood/about-lake/xw",
        },
        {
          label: "优秀毕业生审核",
          name: "biye",
          value: 0,
          url: "/stuGood/good-graduate/xw",
        },
        {
          label: "困难认定审核",
          name: "kn",
          value: 0,
          url: "/hard/pks/xw",
        },
        {
          label: "助学金审核",
          name: "zx",
          value: 0,
          url: "/hard/zxj/xw",
        },
        {
          label: "宿舍管理审核",
          name: "dms",
          value: 0,
          url: "/dormitory/stuDormitoryManage/work",
        },
        // {
        //   label: "勤工助学学生岗位申请审核",
        //   name: "qgzxgw",
        //   value: 0,
        //   url: "/workstudy/stupost/zdls",
        // },
        // {
        //   label: "勤工助学学生工作记录审核",
        //   name: "qgzxgzjl",
        //   value: 0,
        //   url: "/workstudy/worklog/zdls",
        // },
        {
          label: "任务管理审核",
          name: "rwgl",
          value: 0,
          url: "/task/todo",
        },
      ],

      myChartStyle: {
        float: "left",
        width: "400px",
        height: "300px",
        margin: 0,
      }, //图表样式

      fast: [
        {
          src: require("@/assets/icons/index-icon/Icon-Folder.png"),
          url: "",
          text: "操作手册",
        },
        {
          src: require("@/assets/icons/index-icon/Icon-Arrow.png"),
          url: "",
          text: "我的申请",
        },
        {
          src: require("@/assets/icons/index-icon/Icon-Info.png"),
          url: "",
          text: "我的待办",
        },
        {
          src: require("@/assets/icons/index-icon/Icon-Clock.png"),
          url: "",
          text: "综合素质",
        },
        {
          src: require("@/assets/icons/index-icon/Icon-Send.png"),
          url: "",
          text: "我的流程",
        },
        {
          src: require("@/assets/icons/index-icon/Icon-Chart.png"),
          url: "",
          text: "优秀班级",
        },
        {
          src: require("@/assets/icons/index-icon/Icon-Home.png"),
          url: "",
          text: "优秀宿舍",
        },
        {
          src: require("@/assets/icons/index-icon/Icon-Menu.png"),
          url: "",
          text: "已办任务",
        },
      ],

      msg_list: [],
      have_msg: false,
      msg_content: "",
      msgV: false,

      comp_list: [],
      have_comp: false,
      comp_msg: "",
      compV: false,

      init_park_list: [],
    };
  },
  created () {
    this.listMyMsg();
    this.getCompleted();

    this.countXwUnDo();

    //this.countParkStuIn();
  },
  mounted () {
    // this.initEcharts2();
  },
  watch: {
    iamChildType (newVal, oldVal) {
      this.child_list.map((v) => {
        if (v.ruleId == newVal) {
          this.iam_add_record = v.maxScore;
        }
      });
    },
  },
  methods: {
    async countXwUnDo () {
      let res = await countXwUnDo();
      if (res.code == 200) {
        let data = [...res.data];
        this.taskList.map((x) => {
          let temp = data.filter((y) => y.startsWith(x.name));
          if (!isEmpty(temp)) {
            let result = temp[0].split("-")[1];
            x.value = result;
          }
        });
      }
    },

    toRoute (url) {
      if (!isEmpty(url)) {
        this.$router.push(url);
      }
    },

    async countParkStuIn () {
      let res = await countParkStuIn();
      if (res.code == 200) {
        this.init_park_list = [...res.data];
      }
    },
    customColorMethod (percentage) {
      if (percentage < 40) {
        return "#67c23a";
      } else if (percentage < 75) {
        return "#e6a23c";
      } else {
        return "red";
      }
    },

    async initEcharts2 () {
      let year_list = [];
      let dept_list = [];
      let v_list = [];

      let res = await countBiyeYearDept();
      if (res.code == 200) {
        let data = [...res.data];

        let temp1 = groupBy(data, (x) => x.deptName);
        let temp2 = groupBy(data, (y) => y.stuYearName);

        for (let key in temp1) {
          dept_list.push(key.replace('"', "").replace('"', ""));
        }

        for (let key in temp2) {
          year_list.push(key.replace('"', "").replace('"', ""));
        }

        dept_list.map((x) => {
          let temp = {
            name: x,
            type: "line",
            stack: "total",
            data: [],
          };

          year_list.map((y) => {
            let v_data = data.filter(
              (z) => z.stuYearName == y && z.deptName == x
            );

            if (!isEmpty(v_data)) {
              temp.data.push(v_data[0].majorCount);
            } else {
              temp.data.push(0);
            }
          });
          v_list.push(temp);
        });
      }

      let option = {
        tooltip: {
          trigger: "axis",
        },
        legend: {
          data: [...dept_list],
          left: "3%",
          right: "4%",
          bottom: "0%",
          // show: false
        },
        grid: {
          top: "10%",
          left: "3%",
          right: "4%",
          containLabel: true,
        },
        toolbox: {
          feature: {
            saveAsImage: {},
          },
        },
        xAxis: {
          type: "category",
          boundaryGap: false,
          data: [...year_list],
        },
        yAxis: {
          type: "value",
        },
        series: [...v_list],
      };

      const myChart = echarts.init(document.getElementById("mychart2"));
      myChart.setOption(option);
      //随着屏幕大小调节图表
      window.addEventListener("resize", () => {
        myChart.resize();
      });
    },

    async getCompleted () {
      let res = await getCompleted();
      if (res.rows.length > 0) {
        this.have_comp = true;
        this.comp_list = [...res.rows];
      }
    },

    msgVClick (v) {
      this.msg_content = v;
      this.msgV = true;
    },

    //列出我的消息
    async listMyMsg () {
      let res = await listMsg();
      if (res.rows.length > 0) {
        this.have_msg = true;
        this.msg_list = [...res.rows];
      }
    },

    goTarget (href) {
      window.open(href, "_blank");
    },
    getBackColor (i) {
      let color = this.colors[i % 7];
      return {
        "background-color": color,
      };
    },
  },
};
</script>
<style lang="scss" scoped>
.bottom-charts-container {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-around;
}

.bottom-charts-item {
  flex-basis: 50%;
}

.six-action-container {
  display: flex;
  flex-wrap: wrap;
}

.six-action-item {
  flex-basis: 33.33%;
}

.campus-dms-count-container {
  display: flex;
  flex-wrap: wrap;
}

.campus-dms-count-item {
  flex-basis: 33.33%;
}

.stuCountText {
  line-height: 2rem;
  font-size: 1.125rem;
  font-weight: bold;
}

.stuCountNumber {
  font-size: 1rem;
}

.act-text {
  width: 100%;
  left: 1rem;
  margin-top: -1rem;
  z-index: 2;

  .title {
    text-align: left;
    font-size: 1.25rem;
    color: #fff;
  }

  .todo {
    margin-top: 1rem;
    font-size: 6rem;
    color: #fff;
  }
}

.bg-to {
  cursor: pointer;
  z-index: 3;
  position: absolute;
  bottom: 5%;
  right: 3%;
  margin-top: 10px;
  color: white;
}

.bg-cloud {
  text-align: right;
  opacity: 0.5;
  z-index: 0;
  position: absolute;
  bottom: 0;
  right: 0;
  width: 12rem;
  height: 40%;
  background-color: #fdfbfb;
  border-radius: 3.125rem;
  transition: transform 0.3s linear, opacity 0.3s linear;
}

.bg-cloud::before,
.bg-cloud::after {
  content: "";
  position: absolute;
  background-color: #fdfbfb;
  display: block;
  border-radius: 6.25rem;
}

.bg-cloud::before {
  width: 4.25rem;
  height: 4.25rem;
  top: -2rem;
  right: 5.125rem;
}

.bg-cloud::after {
  width: 4.75rem;
  height: 4.75rem;
  top: -2.5rem;
  right: 1rem;
}

.bubble {
  overflow: hidden;
  margin: 0 auto;
  width: 100%;
  height: 170px;
  border-radius: 1rem;
  // background-image: linear-gradient(120deg, rgb(134, 233, 98) 0%, rgb(45, 175, 92) 100%);
  position: relative;
  background-size: cover;
  min-width: 250px;
}

.six-action-to:hover,
.fast-act:hover {
  cursor: pointer;
  transform: scale(1.1);
}

div::-webkit-scrollbar {
  width: 4px;
}

div::-webkit-scrollbar-thumb {
  border-radius: 10px;
  -webkit-box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
  opacity: 0.2;
  background: fade(blue, 60%);
}

div::-webkit-scrollbar-track {
  -webkit-box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
  border-radius: 0;
  background: fade(blue, 30%);
}

.lunbo {
  padding: 0 8px 0 0;
  box-sizing: border-box;
  text-overflow: ellipsis; //超出内容...展示
  word-break: keep-all; //是否折断文本，keep-all表示不折断
  white-space: nowrap; //不换行展示文本
  overflow: hidden; //超出部分隐藏，与text-overflow配合使用
  flex: 1; //这个是跟左侧的图片组成的一个flex布局
}

.arrow {
  width: 0;
  height: 0;
  border-width: 10px;
  border-style: solid;
  border-color: transparent transparent transparent rgb(108, 108, 108);
  position: relative;
  top: 50px;
}

#main {
  background-color: rgb(250, 254, 255);
  padding: 10px 0 10px 20px;
  position: absolute;
  width: 100%;
  height: 100%;
  top: 0px;
  overflow: scroll;
}

.el-card__header {
  border: none;
}

.el-header,
.el-footer {
  background-color: #b3c0d1;
  color: #333;
  text-align: center;
  line-height: 60px;
}

.el-main {
  color: #333;
  margin: 0;

  .box-card {
    margin: 0 auto;
  }

  .six-action {
    height: 40vh;
  }

  .act-img {
    width: 4.75rem;
    height: 4.625rem;
    position: relative;
    top: 10px;
    display: inline-block;
  }

  .act-text {
    display: inline-block;
    font-size: 1.4375rem;
    height: 50px;
    float: right;
    position: relative;
    right: 30px;
    top: 28px;
  }
}
</style>
